package com.homework;

import java.util.Random;

public class demo02 {
    public static void main(String[] args) {
        //定义一个数组，长度为20
        int[] score = new int[20];
        //new随机数
        Random r = new Random();
        System.out.print("正序为：");
        for (int i = 0; i < score.length; i++) {
            score[i] = r.nextInt(0, 101);
            //并用正序打印一边，以便对比
            System.out.print(score[i] + "，");
        }
        System.out.println();
        //倒序打印
        System.out.print("倒叙为：");
        for (int a = 0; a < score.length; a++) {
            System.out.print(score[19 - a] + "，");
        }
        System.out.println();
        //分别定义分数初始的最大、最小值和总分，用循环不断替换更小的和最大的，同时求总分数
        int min = score[0];
        int max = score[0];
        int total = 0;
        for (int b = 0; b < score.length; b++) {
            //获取最低分
            if (min > score[b]) {
                min = score[b];
            }
            //获取最高分
            if (max < score[b]) {
                max = score[b];
            }
            total += score[b];
        }
        System.out.println("最低分为：" + min);
        System.out.println("最高分为：" + max);
        System.out.println("总分为：" + total);
        System.out.println("平均分为：" + (total / score.length));
    }
}